package com.yidu.qx.service;

import com.yidu.qx.action.vo.UserEntityVo;
import com.yidu.qx.dao.CharacterDao;
import com.yidu.qx.domain.QxCharacterEntity;
import com.yidu.qx.domain.QxUserEntity;
import com.yidu.qx.utils.Pages;
import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;

import java.util.*;

/**
 * @program: jurisdiction
 * @description
 * @author: 周佳佳
 * @create: 2019-09-25 14:53
 **/
public class CharacterImpl implements  CharacterService{
    Logger logger= (Logger) Logger.getLogger(String.valueOf(CharacterImpl.class));

    private CharacterDao characterDao;

    public CharacterDao getCharacterDao() {
        return characterDao;
    }

    public void setCharacterDao(CharacterDao characterDao) {
        this.characterDao = characterDao;
    }

    @Override
    public void add(QxCharacterEntity qxCharacterEntity) {
        characterDao.add(qxCharacterEntity);
    }

    @Override
    public void delete(QxCharacterEntity qxCharacterEntity) {
        QxCharacterEntity qxCharacterEntity1 = characterDao.findById(qxCharacterEntity.getChaId());
        qxCharacterEntity1.setChaState("");
        characterDao.update(qxCharacterEntity1);
    }

    @Override
    public void update(QxCharacterEntity qxCharacterEntity) {
        characterDao.update(qxCharacterEntity);
    }

    @Override
    public List<UserEntityVo> findAll(UserEntityVo userEntityVo, Pages pages) {
        return null;
    }

    @Override
    public Map<String,Object> findAll(QxCharacterEntity qxCharacterEntity, Pages pages) {
        Map map = new HashMap();
        List<QxCharacterEntity> list=characterDao.findAll(qxCharacterEntity,pages);

        Long count = characterDao.count(qxCharacterEntity);

        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", list);

        return map;
    }

    @Override
    public Map<String,Object> index(QxUserEntity qxUserEntity) {
        return characterDao.index(qxUserEntity);
    }

    @Override
    public QxCharacterEntity findById(String id) {
        QxCharacterEntity qxCharacterEntity=characterDao.findById(id);
        return qxCharacterEntity;
    }

    @Override
    public List<UserEntityVo> findAllone() {
        List<UserEntityVo> vo=new ArrayList<>();
        List<QxCharacterEntity> list=characterDao.findAllone();
        for (QxCharacterEntity qxCharacterEntity : list) {
            UserEntityVo userEntityVo=new UserEntityVo();
            BeanUtils.copyProperties(qxCharacterEntity,userEntityVo);
            vo.add(userEntityVo);
        }
        return vo;
    }

    @Override
    public Long count(QxCharacterEntity qxCharacterEntity) {
        return characterDao.count(qxCharacterEntity);
    }
}
